package com.heatup.apt.api.service.impl;

import java.util.Date;
import java.util.Map;

import com.heatup.apt.api.service.CoachService;
import com.heatup.apt.api.service.OrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.heatup.apt.common.constants.ErrorCodeConstants;
import com.heatup.apt.common.dao.CoachCallUserMapper;
import com.heatup.apt.model.api.ApiResultModel;
import com.heatup.apt.model.coach.CoachCallUser;
import com.heatup.apt.model.order.OrderInfo;
import com.heatup.apt.model.user.UserInfo;
import com.heatup.apt.api.service.CoachCallUserService;
import com.heatup.apt.api.service.UserService;
import com.baomidou.framework.service.impl.SuperServiceImpl;

/**
 *
 * CoachCallUser 表数据服务层接口实现类
 *
 */
@Service
public class CoachCallUserServiceImpl extends SuperServiceImpl<CoachCallUserMapper, CoachCallUser> implements CoachCallUserService {
	
	private Logger logger = LoggerFactory.getLogger(CoachCallUserServiceImpl.class);
	
	@Autowired
	private OrderService orderService;
	@Autowired
	private CoachService coachService;
	@Autowired
	private UserService userService;
	
	@Autowired
	private CoachCallUserMapper coachCallUserMapper;
	
	/**
	 * 保存教练呼叫学员的电话记录
	 */
	@Override
	public ApiResultModel<Object> saveCoachCallUser(Map<String, Object> parmsMap) {
		logger.info("=========================== saveCoachCallUser start  ============================");
		ApiResultModel<Object>  model = new ApiResultModel<>();
		Integer orderId = (Integer) parmsMap.get("orderId");
		UserInfo coachUserInfo = (UserInfo) parmsMap.get("coachUserInfo");
		model.setMsg("插入成功！");
		model.setRet(model.RET_SUCCESS);
		OrderInfo orderInfo = orderService.selectById(orderId);
		if(orderInfo == null){
			model.setRet(model.getErrorCode());
			model.setErrorCode(ErrorCodeConstants.Code.ORDER_NOT_FIND.getCode());
			model.setMsg(ErrorCodeConstants.Code.ORDER_NOT_FIND.getMessage());
			return model;
		}
		/*UserInfo userInfo = userService.selectById(orderInfo.getUserId());
		CoachInfo coachInfo = coachService.queryCoachByMobile(coachUserInfo.getMobile());*/
		
		CoachCallUser coachCallUser = coachCallUserMapper.returnSaveCoachCallUserData(orderId, coachUserInfo.getMobile());//new CoachCallUser();
		coachCallUser.setCreatedBy(String.valueOf(coachUserInfo.getId()));
		coachCallUser.setCreatedTime(new Date());
		Integer saveCount = coachCallUserMapper.insertSelective(coachCallUser);
		logger.info("=========================== saveCoachCallUser saveCount："+saveCount);
		logger.info("=========================== saveCoachCallUser end  ============================");
		return model;
	}


}